#ifndef ASYNCIMAGEVIEW_H
#define ASYNCIMAGEVIEW_H

#include <QLabel>
#include <QString>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include "imageBll/loadimagebllcallback.h"

class EZThread;
class EZThreadEvent;

class AsyncImageView : public QLabel , public LoadImageBllCallBack
{
    Q_OBJECT
public:
    static QString defaultImgCachePath(const QString &path=QString());
public:
    AsyncImageView(QWidget *parent = 0);
     ~AsyncImageView();
public:
    QString imgUrl() const;

    QString getImgCachePath() const;
    void setImgCachePath(const QString &value);

    void cancelLoad();

    virtual void loadImageFinish(LoadImageBLL */*loadBll*/,LoadImageFinishEvent */*event*/);
private:
    QString _imgUrl;
    QString imgCachePath;

    QNetworkAccessManager *_netManager;
    QNetworkReply *_reply;

    void saveImage(const QPixmap &pixmap);

    EZThreadEvent *_loadImageOnDiskEvent;
    void loadImageOnDisk(EZThread*);
signals:
    void sigLoadImageOnDisFinish();
public slots:
    int loadImageWithUrl(const QString &url);

    void setImageWithPixmap(const QPixmap &);
private slots:
    void onLoadImageOnDiskFinish();
    void loadImageFinish(QNetworkReply*);
};

#endif // ASYNCIMAGEVIEW_H
